﻿using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using WJSHWebApi.DBModel;
using WJSHWebApi.InterFace;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace WJSHWebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserInfo : ControllerBase
    {
        private IDBInterface iDBInterface;
        public UserInfo(IDBInterface dBInterface) 
        {
            iDBInterface=dBInterface;
        }
        [HttpPost]
        public UserResult Post([FromBody] Usertemp value)
        {
           var  Userresult = new UserResult();
            var user = iDBInterface.FirstOrDefault<User_Entity>(x => x.userName == value.UserName && x.passWord == value.Pwd);
            if (user == null) return Userresult;
             var roll = iDBInterface.FirstOrDefault<Role_Entity>(x => x.rol1ID == user.rollID);
            if (roll==null) return Userresult;
            Userresult.UserName = value.UserName;
            Userresult.Result = true;
            Userresult.RawPda = roll.RawPda;
            Userresult.OvenPda = roll.OvenPda;
            Userresult.SlittingPdaUp = roll.SlittingPdaUp;
            Userresult.SlittingPdaDown = roll.SlittingPdaDown;
            Userresult.Finished = roll.Finished;        
            return Userresult;
    }
    }
    public class Usertemp
    {
        public string UserName { get; set; }
        public string Pwd { get; set; }
    }
    public class UserResult 
    {
        public string UserName { get; set; }
        public bool RawPda { get; set; }
     
        public bool OvenPda { get; set; }
        public bool SlittingPdaUp { get; set; }
        public bool SlittingPdaDown { get; set; }
        public bool Finished { get; set; }
        public bool Result { get; set; }
    }
}
